//
//  FillGoodsMoneyTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/27.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "FillGoodsMoneyTableViewCell.h"

@implementation FillGoodsMoneyTableViewCell{
    GLGWLabel * goodsNumLabel;
    GLGWLabel * moneyLabel;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        GLGWLabel * xiaoJilabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
        xiaoJilabel.text = @"商品小计";
        [xiaoJilabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(12));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        //
        goodsNumLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.contentView];
        goodsNumLabel.text = @"共4件 23.564 吨";
        [goodsNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.height.equalTo(xiaoJilabel);
        }];
        //
        GLGWLabel * allMoneyLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
        allMoneyLabel.text = @"商品总金额";
        [allMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.height.equalTo(xiaoJilabel);
            make.top.equalTo(xiaoJilabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(15));
        }];
        //
        moneyLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(18) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.contentView];
        moneyLabel.text = @"¥177149.96";
        [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(xiaoJilabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(12));
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(25)));
        }];
    }
    return self;
}

- (void)setDataModel:(ToPayOrderDataModel *)dataModel
{
    _dataModel = dataModel;
    
    NSArray *arr = dataModel.orderGoods;
    NSInteger coutNum = 0;
    NSInteger coutWight = 0;
    NSDecimalNumber *totalPrice = 0;
    for (ToPayOrderDataOrderGoodsModel *orderGoodsModel in arr) {
        coutNum += orderGoodsModel.goodsNum;
        NSInteger wei = [orderGoodsModel.weightCounting integerValue];
        NSInteger everyWei = wei * orderGoodsModel.goodsNum;
        coutWight += everyWei;
        NSDecimalNumber *pri = 0;
        if (orderGoodsModel.modifyPrice > 0) {
            pri = orderGoodsModel.modifyPrice;
        } else {
            pri = orderGoodsModel.price;
        }
        totalPrice = pri;
    }
    NSString *coutstr = [NSString stringWithFormat:@"%ld",coutNum];
    NSDecimalNumber *coutDeci = [NSDecimalNumber decimalNumberWithString:coutstr];
    NSDecimalNumber *totalPric = [coutDeci decimalNumberByMultiplyingBy:totalPrice];
    goodsNumLabel.text = [NSString stringWithFormat:@"共%ld件 %ld 吨",coutNum,coutWight];
    
    moneyLabel.text = [NSString stringWithFormat:@"¥%@",totalPric];
}

@end
